Functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data
Pure functions
It returns the same result if given the same arguments (it is also referred as deterministic)
It does not cause any observable side effects
Immutability
Unchanging over time or unable to be changed. When data is immutable, its state cannot change after it’s created. If you want to change an immutable object, you can’t. Instead, you create a new object with the new value.
Referential transparency
pure functions + immutable data = referential transparency
Functions as first-class entities
refer to it from constants and variables
pass it as a parameter to other functions
return it as result from other functions
Higher-order functions
takes one or more functions as arguments, or
returns a function as its result
Filter
The filter function expects a true or false value to determine if the element should or should not be included in the result collection.
Map
The map method transforms a collection by applying a function to all of its elements and building a new collection from the returned values.
Reduce
filter by book type
transform the shopping cart into a collection of amount using map